import java.awt.Color;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.geom.Rectangle2D;


public class RectangleChar implements GameObject{

	double x = 0.0;
	double y = 0.0;
	Color c;
	int r;
	//[0] is up [1] is down [2] is left [3] is right
	boolean[] dir = {false, false, false, false};
	String cont = null;

	RectangleChar(String c){
		cont = c;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		r += 2;
		r %= 256;

		if(dir[0]){
			y -= 10;
		}
		if(dir[1]){
			y += 10;
		}
		if(dir[2]){
			x -= 10;
		}
		if(dir[3]){
			x += 10;
		}


	}

	@Override
	public void keyPressed(KeyEvent e) {
		if(cont.equals("udlr")){
			if(e.getKeyCode() == KeyEvent.VK_UP){
				dir[0] = true;
			}
			if(e.getKeyCode() == KeyEvent.VK_DOWN){
				dir[1] = true;
			}
			if(e.getKeyCode() == KeyEvent.VK_LEFT){
				dir[2] = true;
			}
			if(e.getKeyCode() == KeyEvent.VK_RIGHT){
				dir[3] = true;
			}
		}
		else if(cont.equals("wasd")){
			if(e.getKeyCode() == KeyEvent.VK_W){
				dir[0] = true;
			}
			if(e.getKeyCode() == KeyEvent.VK_S){
				dir[1] = true;
			}
			if(e.getKeyCode() == KeyEvent.VK_A){
				dir[2] = true;
			}
			if(e.getKeyCode() == KeyEvent.VK_D){
				dir[3] = true;
			}
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		if(cont.equals("udlr")){
			if(e.getKeyCode() == KeyEvent.VK_UP){
				dir[0] = false;
			}
			if(e.getKeyCode() == KeyEvent.VK_DOWN){
				dir[1] = false;
			}
			if(e.getKeyCode() == KeyEvent.VK_LEFT){
				dir[2] = false;
			}
			if(e.getKeyCode() == KeyEvent.VK_RIGHT){
				dir[3] = false;
			}
		}
		else if(cont.equals("wasd")){
			if(e.getKeyCode() == KeyEvent.VK_W){
				dir[0] = false;
			}
			if(e.getKeyCode() == KeyEvent.VK_S){
				dir[1] = false;
			}
			if(e.getKeyCode() == KeyEvent.VK_A){
				dir[2] = false;
			}
			if(e.getKeyCode() == KeyEvent.VK_D){
				dir[3] = false;
			}
		}
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public Shape getShape() {
		return new Rectangle2D.Double(x, y, 100, 100);
	}

	@Override
	public Color getColor() {
		return new Color(255-r, 0, 0);
	}

	@Override
	public double getX() {
		return x;
	}

	@Override
	public double getY() {
		return y;
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseWheelMoved(MouseWheelEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
